<?php

namespace App\Traits\Relation;

use App\Models\AdminUser;
use App\Models\PrivilegeStation;
use App\Models\StationPrivilege;
use Illuminate\Database\Eloquent\Relations\HasOne;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Eloquent\Relations\Relation;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;

/**
 * 用于定义网点和其他模型的关系
 *
 * @package App\Traits\Relation
 * Date: 2018/06/11
 * @author Tenny
 */
trait StationPrivilegeRelation
{
    /**
     * 获取关联共派账户
     *
     * Date: 2018/06/12
     * @author Tenny
     * @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
     */
    public function admin()
    {
        return $this->HasOne(AdminUser::class, 'id', 'admin_id');
    }

    /**
     * 获取关联权限
     *
     * Date: 2018/06/12
     * @author Tenny
     * @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
     */
    public function privileges()
    {
        return $this->HasOne(PrivilegeStation::class, 'id', 'privilege_id');
    }
}
